<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <meta charset="utf-8">
  <title><!--{$lang.page.index.title}--></title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
  <link rel="stylesheet" href="/static/lay/layui/css/layui.css" media="all">
  <link rel="stylesheet" href="/static/web/css/web.css" media="all">
</head>
<body>

  <div class="layui-fluid">
    <div class="layui-card">
      <div class="layui-card-body" style="padding: 15px;">
        <div class="layui-form-item" style="text-align: center;"><b><!--{$lang.page.public.cateadd}--></b></div>
        <form name="addItem" method="post" lay-filter="component-form-group" class="layui-form">
          <input type="hidden" value="<!--{$diInfo.id}-->" name="id">
            <div class="layui-form-item">

              <div class="layui-inline">
              <label class="layui-form-label"><!--{$lang.page.table.name}--></label>
              <div class="layui-input-inline">
               <input type="text" name="title" value="<!--{$diInfo.title}-->" lay-verify="title" placeholder="<!--{$lang.page.public.pinput}-->" autocomplete="off" class="layui-input" />
              </div>
              </div>

              <div class="layui-inline">
              <label class="layui-form-label"><!--{$lang.page.table.ident}--></label>
              <div class="layui-input-inline">
               <input type="text" name="advcode" value="<!--{$diInfo.advcode}-->" lay-verify="advcode" placeholder="<!--{$lang.page.public.pinput}-->" autocomplete="off" class="layui-input" />
              </div>
              </div>
              
              <div class="layui-inline">
              <label class="layui-form-label"><!--{$lang.page.table.icon}--></label>
              <div class="layui-input-block">
              <input type="radio" name="icon" value="2" title="<!--{$lang.page.table.close}-->" <!--{if $diInfo.icon eq 2 || $diInfo.icon eq 0}--> checked<!--{/if}-->  >&nbsp;&nbsp;<input type="radio" name="icon" value="1" title="<!--{$lang.page.table.normal}-->" <!--{if $diInfo.icon eq 1}--> checked<!--{/if}-->>
              </div>
              </div>

              <div class="layui-inline">
              <label class="layui-form-label"><!--{$lang.page.table.status}--></label>
              <div class="layui-input-block">
              <input type="radio" name="status" value="2" title="<!--{$lang.page.table.close}-->" <!--{if $diInfo.status eq 2 || $diInfo.status eq 0}--> checked<!--{/if}-->  >&nbsp;&nbsp;<input type="radio" name="status" value="1" title="<!--{$lang.page.table.normal}-->" <!--{if $diInfo.status eq 1}--> checked<!--{/if}-->>
              </div>
              </div>

              <div class="layui-inline">
              <div class="layui-input-block">
                <button class="layui-btn" type="button" id="submit" lay-submit lay-filter="submit"><!--{$lang.page.public.submit}--></button>
                <button type="button" class="layui-btn layui-btn-primary" onclick="window.location.href='/admin/web/addcate/'"><!--{$lang.page.public.reset}--></button>
              </div>
              </div>

            </div>

          </form>
          </div>
        
      </div>
    </div>

    <div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-card-body">
            <table id="datalist" lay-filter="datalist"></table>
            <script type="text/html" id="toolbartop">
                <div class="layui-btn-container">
                    <button class="layui-btn layui-btn-sm" lay-event="redatalist"><!--{$lang.page.public.refresh}--></button>
                </div>
            </script>
            <script type="text/html" id="zizeng">{{d.LAY_TABLE_INDEX+1}}</script>
            <script type="text/html" id="bartool">
                <a class="layui-btn layui-btn-xs " href="#" onclick="xadmin.self({title:'<!--{$lang.page.public.edit}-->', url:'?id='+{{d.id}},full:true})"><!--{$lang.page.public.edit}--></a>
                <a class="layui-btn layui-btn-danger layui-btn-xs " href="#" onclick="xadmin.del({url:'catedel',data:{{d.id}} })"><!--{$lang.page.public.del}--></a>
            </script>
        </div>
    </div>
</div>

<script src="/static/lay/layui/layui.js"></script>
  <script type="text/javascript">
    layui.config({
     base: '/static/lay/' //静态资源所在路径
   }).extend({
     xadmin: 'lib/xadmin' //弹窗
   }).use(['jquery', 'xadmin', 'form', 'table'], function(){
        var $ = layui.$
        , form = layui.form
        , table = layui.table
          form.render(null, 'component-form-group');
         /* 自定义验证规则 */
        form.verify({
           title: function(value, item){ //value：表单的值、item：表单的DOM对象
              if(value == ""){
                return '<!--{$lang.page.table.name}--> <!--{$lang.page.public.nocontent}-->';
              }
            }
          ,advcode: function(value, item){ //value：表单的值、item：表单的DOM对象
              if(value == ""){
                 return '<!--{$lang.page.table.ident}--> <!--{$lang.page.public.nocontent}-->';
              }
              if(!(/^[A-Za-z]+$/).test(value)){
              return '<!--{$lang.page.table.ident}--> <!--{$lang.page.public.paraerror}-->';
              }
            }
        });
        let lang={};
        $.ajax({
            url: '/admin/common/lang',
            async:false,
            type: 'post',
            dataType: "json",
            success:function(R){
                if (R.code == 200) {
                    lang=R.lang;
                } else {
                    console.log('data is null');
                }
            },
            error: function (R) {
                console.log('failure to send to database');
            }
        });
        table.render({
            elem: '#datalist'
            , height: 'auto'
            , url: ' ' //数据接口
            , method: 'post'
            , page: true //开启分页
            , limit: 10
            , toolbar: '#toolbartop'
            , defaultToolbar: ['filter', 'exports', 'print']
            , cols: [[ //表头
                {field: 'zizeng', title: function(){ return lang.serial }, align: "center", fixwidth: true, width: 80, templet:'#zizeng'},
                {field: 'title', title: function(){ return lang.name } },
                {field: 'advcode', title: function(){ return lang.ident }},
                {field: 'icon', title: function(){ return lang.icon+lang.status },
                 templet:function(d){
                      if(d.icon==1){
                        return '<button class="layui-btn layui-btn-xs">'+lang.normal+'</button>';
                      }else if(d.icon==2){
                         return '<button class="layui-btn layui-btn-danger layui-btn-xs">'+lang.close+'</button>';
                      }
                 }
               },
                {field: 'status', title: function(){ return lang.status },
                 templet: function(d) {
                       if (d.status == 1) {
                            return '<button class="layui-btn layui-btn-xs">'+lang.normal+'</button>';
                        } else {
                            return '<button class="layui-btn layui-btn-primary layui-btn-xs">'+lang.close+'</button>';
                        }
                      }},
                {fixed: '', title: function(){ return lang.operation }, width: 160, align: 'center', toolbar: '#bartool'}
            ]],
            done: function() {
                  layer.closeAll('loading');
            }
            });


        form.on('submit(submit)', function (data) {
                $('#submit').attr("disabled",true);
                $('#submit').addClass('layui-btn-disabled');
                $.post('/admin/web/catesave/',data.field,function(res){
                    if(res.code == 200){
                        layer.msg(res.msg);
                        setTimeout(() => {
                          window.location.reload();
                        }, 1000);
                    }else{
                        layer.msg(res.msg);
                    }
                })
            return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
        });

        table.on('toolbar(datalist)', function(obj){
            switch(obj.event){
                case 'redatalist':
                    //执行重载
                    table.reload('datalist');
                break;
            };
        });


  });
  </script>
</body>
</html>